package top.vanchor.myblog2back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.vanchor.myblog2back.entity.BlogDealRecord;
import top.vanchor.myblog2back.entity.BlogReport;
import top.vanchor.myblog2back.mapper.BlogDealRecordMapper;
import top.vanchor.myblog2back.service.IBlogDealRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-02-20
 */
@Service
public class BlogDealRecordServiceImpl extends ServiceImpl<BlogDealRecordMapper, BlogDealRecord> implements IBlogDealRecordService {

    @Resource
    private BlogDealRecordMapper mapper;

    @Override
    public int toAddItem(BlogDealRecord dealRecord) {
        return mapper.insert(dealRecord);
    }

    @Override
    public int getCounts(BlogDealRecord dealRecord) {
        QueryWrapper<BlogDealRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("report_type",dealRecord.getReportType());
        wrapper.eq("target_id",dealRecord.getTargetId());
        wrapper.eq("handle_user_id",dealRecord.getHandleUserId());
        wrapper.eq("handle_time",dealRecord.getHandleTime());
        return mapper.selectCount(wrapper);
    }

    @Override
    public int upDateInfo(BlogDealRecord dealRecord) {
        QueryWrapper<BlogDealRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("report_type",dealRecord.getReportType());
        wrapper.eq("target_id",dealRecord.getTargetId());
        wrapper.eq("handle_user_id",dealRecord.getHandleUserId());
        return mapper.update(dealRecord,wrapper);
    }

    @Override
    public PageInfo<BlogDealRecord> getList(Integer pageNo, Integer pageSize, Integer dealType, Integer reportType, Integer status) {
        PageHelper.startPage(pageNo,pageSize);
        return new PageInfo<>(mapper.getList(dealType,reportType,status));
    }
}
